<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="com.sand.myTag" prefix="tag"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form-item">
                    <form method="post" class="layui-form-item" action="${pageContext.request.contextPath}/role_updateRoleAndAuth">
                        <input type="hidden" name="id" value="${roleId}">
                        <div>
                            <c:forEach items="${list}" var="item" varStatus="status2">
                                <input type="checkbox" name="ids"
                                       id="chk${status2.index+1}"
                                       value="${item.one.id}"
                                       onclick="authorityChecked('chk${status2.index+1}"
                                       ${tag:dowCheck(list2,item.one.id)}
                                >
                                <strong>${item.one.name}</strong>
                                <br/>
                                <c:forEach items="${item.oneList}" var="item2" varStatus="status3">
                                    <div style="margin-left: 50px">
                                        <input type="checkbox" name="ids"
                                                id="chk${status2.index+1}_${status3.index+1}"
                                               value="${item2.two.id}"
                                               onclick="authorityChecked('chk${status2.index+1}_${status3.index+1}')"
                                               ${tag:dowCheck(list2, item2.two.id)}
                                        >
                                        ${item2.two.name}
                                        <div style="margin-left: 50px">
                                            <c:forEach items="${item2.twoList}" var="item3" varStatus="status4">
                                                <input type="checkbox" name="ids"
                                                       id="chk${status2.index+1}_${status3.index+1}_${status4.index+1}"
                                                       value="${item3.id}"
                                                       onclick="authorityChecked('chk${status2.index+1}_${status3.index+1}_${status4.index+1}')"
                                                       ${tag:dowCheck(list2, item3.id)}
                                                >
                                                ${item3.name}
                                            </c:forEach>
                                        </div>
                                    </div>
                                </c:forEach>
                            </c:forEach>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit">提交数据</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </fieldset>
    </div>
</div>
<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
<script>
    function authorityChecked(re){
        if($('#'+re).prop('checked')==true){
            $("[id='"+re+"_']").prop('checked',true);
        }else{
            $("[id='"+re+"_']").prop('checked',false);
        }

        var auth=re;
        if(re.lastIndexOf("_")>0){
            auth=re.substr(0,re.lastIndexOf("_"));

            if($("[id^='"+auth+"_']:checked").length<1){
                $("#"+auth).prop('checked',false);
            }else{
                $("#"+auth).prop('checked',true);
            }
        }

        if(auth.lastIndexOf("_")>0){
            var auth2=auth.substr(0,auth.lastIndexOf("_"));

            if($("[id^='"+auth2+"_']:checked").length<1){
                $("#"+auth2).prop('checked',false);
            }else{
                $("#"+auth2).prop('checked',true);
            }
        }
    }
</script>
</body>
</html>